package com.sergiandreplace.kaboom.format.zip;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import com.sergiandreplace.kaboom.format.FormatManager;
import com.sergiandreplace.kaboom.util.MyLog;

public class ZipManager extends FormatManager
{
	private ZipFile zFile;
	

	public ZipManager(String uri)
	{
		super(uri);

	}



	public boolean loadFileInfo()
	{
		try
		{
			zFile = new ZipFile(getUri());
		}
		catch (IOException e)
		{
			zFile = null;
			return false;
		}
		return true;
	}

	public void loadFilenames(String pattern)
	{
		filenames = new ArrayList<String>();
		for (Enumeration<? extends ZipEntry> entries = zFile.entries(); entries.hasMoreElements();)
		{
			ZipEntry zEntry = entries.nextElement();
			String filename = zEntry.getName();
			if (filename.matches(pattern))
			{
				MyLog.l("Filename " + filename + "loaded");
				filenames.add(filename);
			}

		}

		Collections.sort(filenames);
	}

	

	public void loadBitmap(String filename, int size)
	{
		setFormatExtractorThread(new ZipBitmapExtractorThread(this, filename, size, getHandler()));
		super.loadBitmap(filename, size);

	}






}
